#include <iostream>

using namespace std;

class Human { public:void say(); };
class Chinese: public Human {public: void say(); };
class XiaoMing: public Chinese {public:void say(); };

// 继承链  Human --> Chinese --> XiaoMing




int main(int argc, const char** argv) {

    {
        // 使用父类指针, 可以指向任何一个子类对象
        // 使用父类指针调用同名方法时, 优先调用父类方法
        // 父类指针指向子类对象时, 只能调用父类中的方法
        Human *p;
        p = new XiaoMing();
        p->say(); // I am Human
    }

    {
        Chinese *p;
        p = new XiaoMing();
        p->say(); // I am Chinese
    }

    {
        // 使用子类指针无法指向父类对象
        // XiaoMing *p;
        // p = new Human(); // error: invalid conversion from ‘Human*’ to ‘XiaoMing*’
        // p->say(); 
    }    

    return 0;
}

void Human::say() {
    cout << "I am Human" << endl; 
}

void Chinese::say() {
    cout << "I am Chinese" << endl;
}

void XiaoMing::say() {
    cout << "I am XiaoMing" << endl;
}
